package com.ybfenpan.controller.member.member;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.ybfenpan.utils.ContextUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ybfenpan.controller.core.BaseController;
import com.ybfenpan.model.Member;
import com.ybfenpan.model.Pan;
import com.ybfenpan.service.MemberService;
import com.ybfenpan.service.PanService;

@Controller
public class PanMemberController extends BaseController {

    @Resource
    private MemberService memberService;
    @Resource
    private PanService panService;

    @RequestMapping("member/member/pan.shtml")
    public String kuang(HttpServletRequest request, ModelMap model)
            throws Exception {
        Map formMap = getParameterMap(request);
        Member member = ContextUtil.getMember();
        member = this.memberService.getByKey(member.getId());

        Member member1 = null;

        Member member21 = null;
        Member member22 = null;

        Member member31 = null;
        Member member32 = null;
        Member member33 = null;
        Member member34 = null;

        Pan pan = this.panService.getByKey(member.getPanId());
        member1 = this.memberService.getByKey(pan.getPanId());

        if (member1 != null) {
            // 获得第二层
            String loginName1 = member1.getLoginName();
            String phoneNumber1 = loginName1.substring(0, 3) + "****" + loginName1.substring(7, loginName1.length());
            request.setAttribute("phoneNumber1", phoneNumber1);
            member21 = memberService.getByKey(pan.getZuoPanId());

            if (member21 != null) {
                String loginName21 = member21.getLoginName();
                String phoneNumber21 = loginName21.substring(0, 3) + "****" + loginName21.substring(7, loginName21.length());
                request.setAttribute("phoneNumber21", phoneNumber21);
            }

            member22 = memberService.getByKey(pan.getYouPanId());
            if (member22 != null) {
                String loginName22 = member22.getLoginName();
                String phoneNumber22 = loginName22.substring(0, 3) + "****" + loginName22.substring(7, loginName22.length());
                request.setAttribute("phoneNumber22", phoneNumber22);
            }

        }

        // 获得第三层
        if (member21 != null) {

            member31 = memberService.getByKey(pan.getZuoPanZuoId());
            if (member31 != null) {
                String loginName31 = member31.getLoginName();
                String phoneNumber31 = loginName31.substring(0, 3) + "****" + loginName31.substring(7, loginName31.length());
                request.setAttribute("phoneNumber31", phoneNumber31);

            }

            member32 = memberService.getByKey(pan.getZuoPanYouId());
            if (member32 != null) {
                String loginName32 = member32.getLoginName();
                String phoneNumber32 = loginName32.substring(0, 3) + "****" + loginName32.substring(7, loginName32.length());
                request.setAttribute("phoneNumber32", phoneNumber32);

            }

        }
        if (member22 != null) {

            member33 = memberService.getByKey(pan.getYouPanZuoId());
            if (member33 != null) {
                String loginName33 = member33.getLoginName();
                String phoneNumber33 = loginName33.substring(0, 3) + "****" + loginName33.substring(7, loginName33.length());
                request.setAttribute("phoneNumber33", phoneNumber33);

            }

            member34 = memberService.getByKey(pan.getYouPanYouId());
            if (member34 != null) {
                String loginName34 = member34.getLoginName();
                String phoneNumber34 = loginName34.substring(0, 3) + "****" + loginName34.substring(7, loginName34.length());
                request.setAttribute("phoneNumber34", phoneNumber34);

            }

        }
        request.setAttribute("member1", member1);
        request.setAttribute("member21", member21);
        request.setAttribute("member22", member22);
        request.setAttribute("member31", member31);
        request.setAttribute("member32", member32);
        request.setAttribute("member33", member33);
        request.setAttribute("member34", member34);
        return "member/member/pan";
    }

}
